define([
        'app/utils/WebUtils',
        'app/service/GeneralServices',
        'underscore',
        'app/utils/AMUICookieUtils',
        'app/utils/CommonUtils'
        
        
        ], function (
        WebUtils,
        gs,
        _,
        AMUICookieUtils
    ) {
	var opt ={};
	var p1 = {};
	
	opt = p1 = AMUICookieUtils.initializePage(true);
	
	
	gs.admin_setting_init(p1, function(resp){
		if(resp.status == "500"){
			WebUtils.alert("连接错误，请刷新页面重试！");	
			return;
		}
		
		opt.navi_main = "系统设置";
		opt.navi_sub = "配置微讲堂的系统"
		opt.copyrighttext = resp.result.admin_copyright;//"© 2016 版权所有 中研沃兮网络科技（上海）有限公司";

		WebUtils.adminPageInt(opt);
		WebUtils.inputInt($("#wx_id"), resp.result.wx_id);
		WebUtils.inputInt($("#wx_secret"), resp.result.wx_secret);
		WebUtils.inputInt($("#wx_open_id"), resp.result.wx_open_id);
		WebUtils.inputInt($("#wx_open_secret"), resp.result.wx_open_secret);
		
		WebUtils.inputInt($("#wjt-admin-copyright"), resp.result.admin_copyright);
		WebUtils.inputInt($("#wjt-admin-attachment-path"), resp.result.admin_attachment_path);
		WebUtils.inputInt($("#wjt_admin_web_hostname"), resp.result.admin_web_hostname);
		
		
	});
	
	disableEditForWeixinSetting();
	
	function enableEditForWeixinSetting(){
		$(".admin-setting-wx").removeAttr("disabled");
		$(".admin-not-edit").hide();
		$(".admin-edit").show();
	};

	function disableEditForWeixinSetting(){
		$(".admin-setting-wx").prop("disabled","disabled");
		$(".admin-edit").hide();
		$(".admin-not-edit").show();
	};
	
	
	$(".admin-setting-wx-change").click(function(){
		enableEditForWeixinSetting();
	});
	
	$(".admin-setting-wx-verify").click(function(){
		
	});
	
	$(".admin-setting-wx-save").click(function(){
		var $btn = $(this);
		$btn.button('loading');
		
		var p ={
			"useruuid":opt.useruuid,
			"wx_id":$("#wx_id").val(),
			"wx_secret":$("#wx_secret").val(),
			"wx_open_id":$("#wx_open_id").val(),
			"wx_open_secret":$("#wx_open_secret").val()
		};
		gs.wx_setting_save(p,function(resp){
			
			$btn.button('reset');
			disableEditForWeixinSetting();
			
			if(resp.status == "500"){
				if($.isNullStr(resp.result)){
					WebUtils.alert("操作不成功，请重试！");					
				}else{
					WebUtils.alert(resp.result);
				}
			}else{
				
				WebUtils.inputOriginalUpdate($("#wx_id"));
				WebUtils.inputOriginalUpdate($("#wx_secret"));
				WebUtils.inputOriginalUpdate($("#wx_open_id"));
				WebUtils.inputOriginalUpdate($("#wx_open_secret"));
				
				WebUtils.alert("修改成功");
			}
		});
		
	});
	
	$(".admin-setting-wx-cancel").click(function(){
		WebUtils.inputRevert($("#wx_id"));
		WebUtils.inputRevert($("#wx_secret"));
		WebUtils.inputRevert($("#wx_open_id"));
		WebUtils.inputRevert($("#wx_open_secret"));
		
		disableEditForWeixinSetting();
	});
	
	$(".admin-setting-adminpwd-save").click(function(){
		var $btn = $(this);
		$btn.button('loading');
		var p ={
			"useruuid":opt.useruuid,
			"wjt_adminpwd_old":$("#wjt_adminpwd_old").val(),
			"wjt_adminpwd_new":$("#wjt_adminpwd_new").val(),
			"wjt_adminpwd_new2":$("#wjt_adminpwd_new2").val()
		};
		
		if($.isNullStr($("#wjt_adminpwd_new").val())){
			WebUtils.alert("新密码不能为空！");	
			return;
		}
		
		gs.wx_setting_adminpwd_update(p,function(resp){
			
			$btn.button('reset');
			
			if(resp.status == "500"){
				if($.isNullStr(resp.result)){
					WebUtils.alert("操作不成功，请重试！");					
				}else{
					WebUtils.alert(resp.result);
				}
			}else{
				WebUtils.alert("修改成功，您的新密码:"+$("#wjt_adminpwd_new").val());
				WebUtils.inputClear($("#wjt_adminpwd_old"));
				WebUtils.inputClear($("#wjt_adminpwd_new"));
				WebUtils.inputClear($("#wjt_adminpwd_new2"));
			}
			
		});
	});
	

	$(".admin-setting-adminpwd-cancel").click(function(){
		WebUtils.inputClear($("#wjt_adminpwd_old"));
		WebUtils.inputClear($("#wjt_adminpwd_new"));
		WebUtils.inputClear($("#wjt_adminpwd_new2"));
	});
	
	

	$(".wjt-admin-sysinfo-save").click(function(){
		
		var $btn = $(this);
		$btn.button('loading');
		var p ={
			"useruuid":opt.useruuid,
			"wjt_admin_copyright":$("#wjt-admin-copyright").val(),
			"wjt_admin_attachment_path": $("#wjt-admin-attachment-path").val(),
			"wjt_admin_web_hostname":$("#wjt_admin_web_hostname").val()
		};
		
		gs.wjt_admin_sysinfo_save(p,function(resp){
			
			$btn.button('reset');
			
			if(resp.status == "500"){
				if($.isNullStr(resp.result)){
					WebUtils.alert("操作不成功，请重试！");					
				}else{
					WebUtils.alert(resp.result);
				}
			}else{
				WebUtils.alert("修改成功");
				WebUtils.inputOriginalUpdate($("#wjt-admin-copyright"));
				WebUtils.inputOriginalUpdate($("#wjt-admin-attachment-path"));
				WebUtils.inputOriginalUpdate($("#wjt_admin_web_hostname"));
				$(".wjt-admin-copyright").text($("#wjt-admin-copyright").val());
			}
			
		});
		
		
		
		
	});
	
	

	$(".wjt-admin-sysinfo-cancel").click(function(){
		WebUtils.inputRevert($("#wjt-admin-copyright"));
		WebUtils.inputRevert($("#wjt-admin-attachment-path"));
		WebUtils.inputRevert($("#wjt_admin_web_hostname"));
		
	});
	
	return;
});